from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import sys, MySQLdb
db = MySQLdb.connect("localhost", "root", "qaz123456", "mysql", charset='utf8' )
cursor = db.cursor()
cursor.execute("select * from help_topic")
results = cursor.fetchall()
app = QApplication(sys.argv)
table = QTableWidget(637, 6)
table.setSelectionMode(QAbstractItemView.ExtendedSelection)
table.setRowCount(len(results))
table.setColumnCount(6)
cursor.execute("select column_name from information_schema.columns  where table_name='help_topic'")
col_results = cursor.fetchall()
label_list = []
for row in col_results:
    label_list.append(str(row[0]))
table.setHorizontalHeaderLabels(label_list)
table.setColumnWidth(1, 40)
table.setColumnWidth(2, 100)
table.setColumnWidth(3, 50)
table.setColumnWidth(4, 200)
table.setColumnWidth(5, 40)
table.setColumnWidth(6, 40)
i = 0
for row in results:
    j = 0
    for item in row:
        cell = QTableWidgetItem(str(item))
        table.setItem(i, j, cell)
        j = j + 1
    i = i + 1

main = QMainWindow()
main.resize(1200,800)
main.setWindowTitle("查询表数据")
main.setCentralWidget(table)
main.show()
db.close()
sys.exit(app.exec_())